﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditStudent.aspx.cs" Inherits="Teacher_EditUser" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../layui/layui.js"></script>
    <link href="../layui/css/layui.css" rel="stylesheet" />
    <script src="../JS/jquery-3.3.1.min.js"></script>
    <script>
        layui.use(['form', 'layedit', 'laydate', 'table'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
                , table = layui.table;

            //监听select 变化
            var parent_json = eval('(' + window.parent.TableJson + ')');
            loadData(parent_json);

            table.render({
                elem: '#CorrectAA'
                , url: '/handler/EMSsystem.ashx?Action=PAPERLIST' //数据接口
                , limit: 6000
                , cols: [[ //表头
                    { type: 'checkbox', title: '选择' },
                    { field: 'USER_NAME', title: '姓名', width: 100 }
                    , { field: 'c_name', title: '课程名称', width: 300 }
                    , { field: 'PaperName', title: '试卷名称', width: 300 }
                    , { field: 'PaperID', title: '试卷ID', width: 100 }
                ]]
            });

            //复选事件
            $("#btncheckbox").click(function () {
                var PaperIDList = "";
                var checkStatus = layui.table.checkStatus('CorrectAA').data;
                for (i = 0; i < checkStatus.length; i++) {
                    if (i == checkStatus.length - 1) {
                        PaperIDList = PaperIDList + checkStatus[i].PaperID;
                    }
                    else {
                        PaperIDList = PaperIDList + checkStatus[i].PaperID + ",";
                    }
                }

                var thisurl = '/handler/EMSsystem.ashx?Action=UserList&Method=Update&ID=' + $("input[name='ID']").val();
                $.ajax({
                    url: thisurl
                    , data: { "PaperIDList": PaperIDList, "USER_NAME": $("input[name='USER_NAME']").val(), "LOGIN_NAME": $("input[name='LOGIN_NAME']").val(), "LOGIN_PASS": $("input[name='LOGIN_PASS']").val(), "COMPANY": $("input[name='COMPANY']").val(), "DEPARTMENT": $("input[name='DEPARTMENT']").val() }
                    , success: function (obj) {
                        var back = eval('(' + obj + ')');
                        var code = back.code;
                        var msg = back.msg;
                        if (code === "0") {
                            parent.layer.msg(msg);
                            $("#btnClose").click();
                        }
                        else {
                            layer.msg(msg);
                        }
                    }
                });
            });

            $("#btnClose").click(function () {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);//关闭当前页
                // window.parent.location.replace(location.href)//刷新父级页面

            });




            function loadData(obj) {
                var key, value, tagName, type, arr;
                for (x in obj) {
                    key = x;
                    value = obj[x];
                    $("[name='" + key + "'],[name='" + key + "[]']").each(function () {
                        tagName = $(this)[0].tagName;
                        type = $(this).attr('type');
                        if (tagName == 'INPUT') {
                            if (type == 'radio') {
                                $(this).attr('checked', $(this).val() == value);
                            } else if (type == 'checkbox') {
                                arr = value.split(',');
                                for (var i = 0; i < arr.length; i++) {
                                    if ($(this).val() == arr[i]) {
                                        $(this).attr('checked', true);
                                        break;
                                    }
                                }
                            } else {
                                $(this).val(value);
                            }
                        } else if (tagName == 'SELECT' || tagName == 'TEXTAREA') {
                            $(this).val(value);
                        }

                    });
                }
            }
        });
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form id="mainform" class="layui-form" name="mainform" lay-filter="component-form-group" method="post">
                    <div class="layui-form-item" style="display: none">
                        <label class="layui-form-label">用户ID</label>
                        <div class="layui-input-block">
                            <input type="text" name="ID" lay-verify="title" autocomplete="off" readonly="true" placeholder="USER_ID" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">姓名</label>
                        <div class="layui-input-block">
                            <input type="text" name="USER_NAME" lay-verify="title" autocomplete="off" placeholder="姓名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">登录名称</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <input type="text" id="LOGIN_NAME" name="LOGIN_NAME" lay-verify="title" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">登录密码</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <input type="text" id="LOGIN_PASS" name="LOGIN_PASS" lay-verify="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">公司名称</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <input type="text" id="COMPANY" name="COMPANY" lay-verify="title" autocomplete="off" class="layui-input">
                        </div>
                        <label class="layui-form-label">所在部门</label>
                        <div class="layui-input-inline" style="width: 200px">
                            <input type="text" id="DEPARTMENT" name="DEPARTMENT" lay-verify="title" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <table id="CorrectAA" lay-filter="CorrectAA"></table>

                    <div class="layui-btn-container">
                        <button class="layui-btn" type="button" id="btncheckbox">确定</button>
                        <button class="layui-btn layui-btn-danger" id="btnClose">取消</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

</body>
</html>
